package ntut.andengine.physics;

import org.anddev.andengine.extension.physics.box2d.PhysicsWorld;

import com.badlogic.gdx.math.Vector2;

public class PauseablePhysicsWorld extends PhysicsWorld {

	protected boolean paused;

	public PauseablePhysicsWorld(Vector2 pGravity, boolean pAllowSleep, int pVelocityIterations, int pPositionIterations) {
		super(pGravity, pAllowSleep, pVelocityIterations, pPositionIterations);
	}

	public PauseablePhysicsWorld(Vector2 pGravity, boolean pAllowSleep) {
		super(pGravity, pAllowSleep);
	}

	@Override
	public void onUpdate(float pSecondsElapsed) {
		if (!paused) {
			this.mRunnableHandler.onUpdate(pSecondsElapsed);
			this.mWorld.step(pSecondsElapsed, this.mVelocityIterations,
					this.mPositionIterations);
			this.mPhysicsConnectorManager.onUpdate(pSecondsElapsed);
		} else {
			this.mRunnableHandler.onUpdate(pSecondsElapsed);
			this.mPhysicsConnectorManager.onUpdate(pSecondsElapsed);
		}
	}

	public boolean isPaused() {
		return paused;
	}

	public void setPaused(boolean paused) {
		this.paused = paused;
	}
}
